1 <?php
2
3 session_start();
4 require "admin/includes/functions.php";
5 require "admin/includes/db.php";
6
7 ?>
8
9 <?php
10
11 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12 // Section 1 (if user attempts to add something to the cart from the product page)
13 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14 if (isset($_GET['fid']) && isset($_GET['qty'])) {
15 $fid = $_GET['fid'];
16 $qty = isset($_GET['qty']) ? (int)$_GET['qty'] : 1;
17 $wasFound = false;
18 $i = 0;
19 // If the cart session variable is not set or cart array is empty
20 if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
21 // RUN IF THE CART IS EMPTY OR NOT SET
22 $_SESSION["cart_array"] = array(0 => array("item_id" => $fid, "quantity" => $qty));
23 } else {
24
25 $qty = isset($_GET['qty']) ? (int)$_GET['qty'] : 1;
26
27 // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
28 foreach ($_SESSION["cart_array"] as $each_item) {
29 $i++;
30 while (list($key, $value) = each($each_item)) {
31 if ($key == "item_id" && $value == $fid) {
32 // That item is in cart already so let's adjust its quantity using array_splice()
33 array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $fid, "quantity" => $each_item['quantity'] + $qty)));
34 $wasFound = true;
35 } // close if condition
36 } // close while loop
37 } // close foreach loop
38 if ($wasFound == false) {
39 array_push($_SESSION["cart_array"], array("item_id" => $fid, "quantity" => $qty));
40 }
41 }
42 header("location: basket.php");
43 exit();
44 }
45
46 ?>
47
48 <?php
49
50 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 // Section 2 (if user chooses to empty their shopping cart)
52 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53 if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
54 unset($_SESSION["cart_array"]);
55 }
56
57 ?>
58
59
60
61 <?php
62
63 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64 // Section 4 (if user wants to remove an item from cart)
65 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") {
67 // Access the array and run code to remove that array index
68 $key_to_remove = $_POST['index_to_remove'];
69 if (count($_SESSION["cart_array"]) <= 1) {
70 unset($_SESSION["cart_array"]);
71 } else {
72 unset($_SESSION["cart_array"]["$key_to_remove"]);
73 sort($_SESSION["cart_array"]);
74 }
75 }
76
77 ?>
78
79 <?php
80
81 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 // Section 5 (render the cart for the user to view on the page)
83 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 $cartOutput = "";
85 $cartTotal = "";
86 $chkbtn = "";
87 $empty_cart = "";
88 $chkprice = "";
89 $product_id_array = "";
90
91 if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
92
93 $cartOutput = "<h3 style=' text-align: center; font-weight: lighter; padding: 10px 0px; background: #ffeeee; color: #333;'>Bạn chưa gọi tách trà sữa nào</h3>";
94
95 }else{
96
97 $cartOutput = "<div class='single_order_head'>
98
99 <h3>Tên</h3>
100 <h3>Giá(N)</h3>
101 <h3>Số lượng</h3>
102 <h3>Tổng tiền</h3>
103 <h3>Xóa</h3>
104
105 </div>";
106
107
108 $i = 0;
109
110 foreach ($_SESSION["cart_array"] as $each_item) {
111 $item_id = $each_item['item_id'];
112 $sql = $db->query("SELECT * FROM food WHERE id='$item_id' LIMIT 1");
113 while ($row = $sql->fetch_assoc()) {
114
115 $foodName = $row['food_name'];
116 $price = $row['food_price'];
117
118 }
119 $pricetotal = $price * $each_item['quantity'];
120 $cartTotal = $pricetotal + $cartTotal;
121
122 // Dynamic Checkout Btn Assembly
123 $x = $i + 1;
124
125 $empty_cart = '<div class="empty_cart">
126
127 <a href="basket.php?cmd=emptycart">Giỏ hàng</a>
128
129 </div>';
130
131 $chkbtn = '<div class="checkout">
132
133 <a href="#" onclick="show_overlay(); return false">Kiểm tra bàn trống</a>
134
135 </div>';
136
137 // Create the product array variable
138 $product_id_array .= "$foodName-".$each_item['quantity'].", ";
139
140 $cartOutput .= '<form style="display: inline; padding: 0; margin: 0;" action="basket.php" method="post">
141
142 <div class="single_order">
143
144 <p>' . $foodName . '</p>
145 <p>' . $price . '</p>
146 <p><select name="quantity" id="'.$item_id.'" onChange="update_qty(\''.$item_id.'\')">
147 '.render_options($each_item['quantity'], $item_id).'
148 </select></p>
149 <p id="ajax_qty_'.$item_id.'">'.$pricetotal.'</p>
150 <p><input name="deleteBtn' . $item_id . '" class="remove" onclick="return verify_choice();" type="submit" value="x" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></p>
151
152 </div>
153
154 </form>';
155
156 $chkprice .= '<input type="hidden" id="chkprice" name="chkprice" value="'.$cartTotal.'" />';
157 $chkfood = '<input type="hidden" id="chkfood" name="chkfood" value="'.$product_id_array.'" />';
158
159 $i++;
160 }
161
162 $cartTotal = '<p class="p_total"><span>Tổng tiền</span> : #'.$cartTotal.'</p>';
163
164 }
165
166 ?>
167
168 <!Doctype html>
169
170 <html lang="en">
171 <meta charset="utf-8" />
172 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
173 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
174
175 <meta name="description" content="" />
176
177 <meta name="keywords" content="" />
178
179 <head>
180
181 <title>Trà sữa khởi nguồn cảm hứng</title>
182
183 <link rel="stylesheet" href="css/main.css" />
184
185 <script src="js/jquery.min.js" ></script>
186
187 <script src="js/myscript.js"></script>
188
189 </head>
190
191 <body>
192
193 <?php require "includes/header.php"; ?>
194
195 <div class="parallax_basket" onclick="remove_class()">
196
197 <div class="parallax_head_basket">
198
199 <h2>Giỏ hàng</h2>
200 <h3></h3>
201
202 </div>
203
204 </div>
205
206 <div class="content remove_pad" onclick="remove_class()">
207
208 <div class="inner_content on_parallax">
209
210 <h2><span class="cart">Trà sữa thơm ngon</span></h2>
211
212 <div class="order_holder">
213
214 <?php echo $cartOutput; ?>
215
216 </div>
217
218 <?php echo $cartTotal; ?>
219
220 <div class="checkout_section">
221
222 <?php echo $empty_cart; ?>
223
224 <?php echo $chkbtn; ?>
225
226 </div>
227
228 </div>
229
230 </div>
231
232 <div class="content" onclick="remove_class()">
233
234 <div class="inner_content">
235
236 <div class="contact">
237
238 <div class="left">
239
240 <h3>Địa chỉ</h3>
241 <p>247 Lê Trọng Thấn - Thanh Xuân</p>
242 <p>Hà Nội</p>
243
244 </div>
245
246 <div class="left">
247
248 <h3>Liên hệ</h3>
249 <p>0972949801</p>
250 <p>trasuathomngon@gmail.com</p>
251
252 </div>
253
254 <p class="left"></p>
255
256 <div class="icon_holder">
257
258 <a href="#"><img src="image/icons/Facebook.png" alt="image/icons/Facebook.png" /></a>
259 <a href="#"><img src="image/icons/Google+.png" alt="image/icons/Google+.png" /></a>
260 <a href="#"><img src="image/icons/Twitter.png" alt="image/icons/Twitter.png" /></a>
261
262 </div>
263
264 </div>
265
266 </div>
267
268 </div>
269
270 <div class="footer_parallax" onclick="remove_class()">
271
272 <div class="on_footer_parallax">
273
274 <p>© <?php echo strftime("%Y", time()); ?> <span>Trà Sữa Milk Tea</span>. Hương Vị Thơm - Chuẩn Vị Ngon</p>
275
276 </div>
277
278 </div>
279
280 <!---------Contact Information---------->
281
282 <div class="overlay" id="overlay" onclick="hide_overlay()"></div>
283
284 <div class="info_holder">
285
286 <p class="close_p"><span class="close_sp" onclick="hide_overlay()"></span></p>
287
288 <h2><span class="tag">Hoàn thành đơn hàng của bạn</span></h2>
289
290 <form method="post" action="" onSubmit="validate_input(); return false">
291
292 <div class="form_group">
293
294 <div class="form_group">
295
296 <label>Họ và tên</label>
297 <input type="text" id="name" name="name" placeholder="Họ và tên" required>
298
299 </div>
300
301 <div class="form_group">
302
303 <label>Địa chỉ</label>
304 <input type="text" id="addr" name="addr" placeholder="Địa chỉ" required>
305
306 </div>
307
308 <div class="form_group">
309
310 <label>Email</label>
311 <input type="Email" id="email" name="email" placeholder="Địa chỉ email" required>
312
313 </div>
314
315 <div class="form_group">
316
317 <label>Di Động</label>
318 <input type="text" id="phone" name="phone" placeholder="Số điện thoại" required>
319
320 <?php echo $chkfood; ?>
321
322 <?php echo $chkprice; ?>
323
324 </div>
325
326 <div class="form_group">
327
328 <input type="submit" class="submit" value="Đặt Hàng" />
329
330 </div>
331
332 </div>
333
334 </form>
335
336 </div>
337
338 </body>
339
340 </html>